<template>
  <main class="content-area">
    <div class="tabs">
      <div v-for="(content, tab) in openTabs" :key="tab" @click="$emit('select-tab', tab)">
        {{ tab }}
        <button @click.stop="$emit('close-tab', tab)">x</button>
      </div>
    </div>
    <div class="tab-content">
      <div v-for="(content, tab) in filteredTabs" :key="tab">
        {{ content }}
      </div>
    </div>
  </main>
</template>

<script>
export default {
  props: {
    currentTab: {
      type: String,
      required: true
    },
    openTabs: {
      type: Object,
      required: true
    }
  },
  computed: {
    filteredTabs() {
      return Object.entries(this.openTabs)
          .filter(([tab]) => tab === this.currentTab)
          .reduce((acc, [tab, content]) => {
            acc[tab] = content;
            return acc;
          }, {});
    }
  }
};
</script>

<style scoped>
.content-area {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.tabs {
  display: flex;
  background-color: #ddd;
  padding: 10px;
}

.tabs div {
  margin-right: 10px;
  padding: 5px 10px;
  cursor: pointer;
}

.tab-content {
  flex-grow: 1;
  padding: 20px;
}
</style>